package com.my.interview.cocurrency;

import java.util.Random;
import java.util.concurrent.ForkJoinPool;

public class MyTest {

    public static void main(String[] args) {

        long [] array = new long [400];
        Random random = new Random();
        for(int i =0;i < array.length;i++){
            array[i] = random.nextLong();
        }

        ForkJoinTask task = new ForkJoinTask(0, array.length-1, array);
        //最大并发数为4
        ForkJoinPool forkJoinPool = new ForkJoinPool(4);
        long start = System.currentTimeMillis();
        //invoke 提交Fork/Join任务并发执行，然后获得异步执行结果
        long res = forkJoinPool.invoke(task);
        long end = System.currentTimeMillis();

        System.out.println("Fork/join sum :" + res + " in " + (end - start) + "ms");

    }
}


